/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.firstpart.location.mapper.OrderNoticeMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.firstpart.location.mapper;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.location.entity.OrderNoticeEntity;

import java.sql.Types;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class OrderNoticeMapperImpl {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;

    public List<OrderNoticeEntity> selectByBatchno(String orderid, String batchno, int orderType, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_ordernotice  where `type` = ? and status=0  and `orderid` = ? and pickbatchno=?  and dr=0 and ytenant_id=?;\n";
        parameter.addParamWithType(orderType, Types.INTEGER);
		parameter.addParam(orderid);
		parameter.addParam(batchno);
		parameter.addParam(tenant_id);

        ResultSetProcessor processor = new AutoBeanListProcessor(new OrderNoticeEntity());
        return (List<OrderNoticeEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }


    public int insertSelective(OrderNoticeEntity record) {
        
        return 0;
    }


    public int updateByPrimaryKeySelective(OrderNoticeEntity record) {
        
        return 0;
    }


    public int insert(OrderNoticeEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxq_ordernotice (`id`, `type`,  `actioncode`, `transtype`,  `orderid`, `ordercode`,  `orderdetailids`, `sourceid`,  `sourcecode`, `sourcedetailids`,  `firstsourceid`, `firstsourcecode`,  `firstsourcedetailids`, `status`,  `ytenant_id`, `creator`,  `auditstatus`, `repickstatus`, `pickbatchno`,  `remark`, `remarkyonyou`, `remarkdxq`,  `modifier`) values (?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?, ?,  ?, ?, ?,  ?)\n";
        parameter.addParamWithType(record.getId(), Types.INTEGER);
		parameter.addParamWithType(record.getType(), Types.INTEGER);
		parameter.addParamWithType(record.getActioncode(), Types.VARCHAR);
		parameter.addParamWithType(record.getTranstype(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrdercode(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderdetailids(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourceid(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourcecode(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourcedetailids(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourceid(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourcecode(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourcedetailids(), Types.VARCHAR);
		parameter.addParamWithType(record.getStatus(), Types.INTEGER);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getAuditstatus(), Types.INTEGER);
		parameter.addParamWithType(record.getRepickstatus(), Types.INTEGER);
		parameter.addParamWithType(record.getPickbatchno(), Types.VARCHAR);
		parameter.addParamWithType(record.getRemark(), Types.VARCHAR);
		parameter.addParamWithType(record.getRemarkyonyou(), Types.VARCHAR);
		parameter.addParamWithType(record.getRemarkdxq(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public List<OrderNoticeEntity> selectByOrderType(int orderType, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_ordernotice  where `type` = ? and status=0 and dr=0 and ytenant_id=?;\n";
        parameter.addParamWithType(orderType, Types.INTEGER);
		parameter.addParam(tenant_id);

        ResultSetProcessor processor = new AutoBeanListProcessor(new OrderNoticeEntity());
        return (List<OrderNoticeEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }


    public OrderNoticeEntity selectByPrimaryKey(Integer id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxq_ordernotice where `id` = ?\n";
        parameter.addParamWithType(id, Types.INTEGER);

        ResultSetProcessor processor = new AutoBeanProcessor(new OrderNoticeEntity());
        return (OrderNoticeEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }


    public int EditEntityStatus(String orderid, int type, int status, String modifier, int auditstatus, String pickbatchno, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" update dxq_ordernotice set `auditstatus` = ?, `status` = ?, `modifier` = ? where `orderid` = ? and `type` = ? ");
		parameter.addParamWithType(auditstatus, Types.INTEGER);
		parameter.addParamWithType(status, Types.INTEGER);
		parameter.addParamWithType(modifier, Types.VARCHAR);
		parameter.addParamWithType(orderid, Types.VARCHAR);
		parameter.addParamWithType(type, Types.INTEGER);
		if (pickbatchno != null && !"".equals(pickbatchno)) {
			sqlBuilder.append(" and pickbatchno=? ");
			parameter.addParam(pickbatchno);
		}
		sqlBuilder.append(" and dr =0 and ytenant_id=?; ");
		parameter.addParam(tenant_id);

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }


    public List<OrderNoticeEntity> selectByType(List<String> strList, String transtype, int orderType, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select * from dxq_ordernotice where `type` = ? and transtype=? ");
		parameter.addParamWithType(orderType, Types.INTEGER);
		parameter.addParam(transtype);
		if (CollectionUtil.isNotEmpty(strList)) {
			sqlBuilder.append(" and `orderid` in ( ");
			String separator0 = " , ";
			for (int index = 0; index < strList.size(); index++) {
				String item = strList.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < strList.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}
		sqlBuilder.append(" and dr=0 and ytenant_id=?; ");
		parameter.addParam(tenant_id);

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new OrderNoticeEntity());
        return (List<OrderNoticeEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }


    public int updateByPrimaryKey(OrderNoticeEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxq_ordernotice set `type` = ?, `actioncode` = ?, `transtype` = ?, `orderid` = ?, `ordercode` = ?, `orderdetailids` = ?, `sourceid` = ?, `sourcecode` = ?, `sourcedetailids` = ?, `firstsourceid` = ?, `firstsourcecode` = ?, `firstsourcedetailids` = ?, `status` = ?, `dr` = ?, `ytenant_id` = ?, `creator` = ?, `auditstatus` = ?, `repickstatus` = ?, `pickbatchno` = ?, `remarkyonyou` = ?, `remarkdxq` = ?, `remark` = ?, `modifier` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getType(), Types.INTEGER);
		parameter.addParamWithType(record.getActioncode(), Types.VARCHAR);
		parameter.addParamWithType(record.getTranstype(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrdercode(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderdetailids(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourceid(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourcecode(), Types.VARCHAR);
		parameter.addParamWithType(record.getSourcedetailids(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourceid(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourcecode(), Types.VARCHAR);
		parameter.addParamWithType(record.getFirstsourcedetailids(), Types.VARCHAR);
		parameter.addParamWithType(record.getStatus(), Types.INTEGER);
		parameter.addParamWithType(record.getDr(), Types.SMALLINT);
		parameter.addParamWithType(record.getYtenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getAuditstatus(), Types.INTEGER);
		parameter.addParamWithType(record.getRepickstatus(), Types.INTEGER);
		parameter.addParamWithType(record.getPickbatchno(), Types.VARCHAR);
		parameter.addParamWithType(record.getRemarkyonyou(), Types.VARCHAR);
		parameter.addParamWithType(record.getRemarkdxq(), Types.VARCHAR);
		parameter.addParamWithType(record.getRemark(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getId(), Types.INTEGER);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int EditEntityAuditstatus(String orderid, int type, int auditstatus, String modifier, String pickbatchno, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxq_ordernotice   set `auditstatus` = ?, `modifier` = ?  where `type` = ?  and dr =0 and ytenant_id=?  and `pickbatchno` = ? and `orderid` = ?\n";
        parameter.addParamWithType(auditstatus, Types.INTEGER);
		parameter.addParamWithType(modifier, Types.VARCHAR);
		parameter.addParamWithType(type, Types.INTEGER);
		parameter.addParam(tenant_id);
		parameter.addParamWithType(pickbatchno, Types.VARCHAR);
		parameter.addParamWithType(orderid, Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int deleteByPrimaryKeys(List<Integer> ids, String tenant_id) {
		if (ids == null || ids.size()==0) return 0;
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" delete from dxq_ordernotice where dr=0 and ytenant_id=? ");
		parameter.addParam(tenant_id);
		if (CollectionUtil.isNotEmpty(ids)) {
			sqlBuilder.append(" and `id` in ( ");
			String separator0 = " , ";
			for (int index = 0; index < ids.size(); index++) {
				Integer item = ids.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < ids.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}else{
			sqlBuilder.append(" and `id` in ( '' )");
		}

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int insertBatch(List<OrderNoticeEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxq_ordernotice (`id`, `type`, `actioncode`, `transtype`, `orderid`, `ordercode`, `orderdetailids`, `sourceid`, `sourcecode`, `sourcedetailids`, `firstsourceid`, `firstsourcecode`, `firstsourcedetailids`, `status`, `ytenant_id`, `creator`, `auditstatus`, `repickstatus`, `pickbatchno`, `remark`, `remarkyonyou`, `remarkdxq`, `modifier`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				OrderNoticeEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.INTEGER);
				parameter.addParamWithType(item.getType(), Types.INTEGER);
				parameter.addParamWithType(item.getActioncode(), Types.VARCHAR);
				parameter.addParamWithType(item.getTranstype(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrderid(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrdercode(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrderdetailids(), Types.VARCHAR);
				parameter.addParamWithType(item.getSourceid(), Types.VARCHAR);
				parameter.addParamWithType(item.getSourcecode(), Types.VARCHAR);
				parameter.addParamWithType(item.getSourcedetailids(), Types.VARCHAR);
				parameter.addParamWithType(item.getFirstsourceid(), Types.VARCHAR);
				parameter.addParamWithType(item.getFirstsourcecode(), Types.VARCHAR);
				parameter.addParamWithType(item.getFirstsourcedetailids(), Types.VARCHAR);
				parameter.addParamWithType(item.getStatus(), Types.INTEGER);
				parameter.addParamWithType(item.getTenant_id(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreator(), Types.VARCHAR);
				parameter.addParamWithType(item.getAuditstatus(), Types.INTEGER);
				parameter.addParamWithType(item.getRepickstatus(), Types.INTEGER);
				parameter.addParamWithType(item.getPickbatchno(), Types.VARCHAR);
				parameter.addParamWithType(item.getRemark(), Types.VARCHAR);
				parameter.addParamWithType(item.getRemarkyonyou(), Types.VARCHAR);
				parameter.addParamWithType(item.getRemarkdxq(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifier(), Types.VARCHAR);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE actioncode=VALUES(actioncode),transtype=VALUES(transtype) ,orderid=VALUES(orderid),ordercode=VALUES(ordercode) ,orderdetailids=VALUES(orderdetailids),sourceid=VALUES(sourceid) ,sourcecode=VALUES(sourcecode),sourcedetailids=VALUES(sourcedetailids) ,firstsourceid=VALUES(firstsourceid),firstsourcecode=VALUES(firstsourcecode) ,firstsourcedetailids=VALUES(firstsourcedetailids),status=VALUES(status) ,auditstatus=VALUES(auditstatus),repickstatus=VALUES(repickstatus) ,pickbatchno=VALUES(pickbatchno),remark=VALUES(remark) ,remarkyonyou=VALUES(remarkyonyou),remarkdxq=VALUES(remarkdxq) ,modifier=VALUES(modifier) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int deleteByPrimaryKey(Integer id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxq_ordernotice where `id` = ?\n";
        parameter.addParamWithType(id, Types.INTEGER);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int EditEntityStatusForPick(String orderid, int type, int repickstatus, String batchno, int status, String modifier, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxq_ordernotice   set `status` = ?, `modifier` = ?  where dr =0 and ytenant_id=?  and `orderid` = ?  and `type`= ?   and `repickstatus` = ?  and `pickbatchno` = ? ;\n";
        parameter.addParamWithType(status, Types.INTEGER);
		parameter.addParamWithType(modifier, Types.VARCHAR);
		parameter.addParam(tenant_id);
		parameter.addParamWithType(orderid, Types.VARCHAR);
		parameter.addParamWithType(type, Types.INTEGER);
		parameter.addParamWithType(repickstatus, Types.INTEGER);
		parameter.addParamWithType(batchno, Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }


    public int editByPrimaryKeys(List<Integer> ids, String tenant_id) {
		if (ids == null || ids.size()==0) return 0;
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append("update dxq_ordernotice set dr = 1 where dr=0 and ytenant_id=? ");
		parameter.addParam(tenant_id);
		if (CollectionUtil.isNotEmpty(ids)) {
			sqlBuilder.append(" and `id` in  ( ");
			String separator0 = " , ";
			for (int index = 0; index < ids.size(); index++) {
				Integer item = ids.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < ids.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}else{
			sqlBuilder.append(" and `id` in  ( '' )");
		}

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

}
